﻿Imports System.Data.SqlClient
Imports System.Net.Mail

Module IndemnityModule

    ''Local
    'Public strConn As String = "data source=(local);initial catalog=Oasis-IBS-BrokerVision;integrated security=SSPI;"
    'Public FTPUserName As String = ""
    'Public FTPPassword As String = ""
    'Public FTPAddress As String = "D:\Systems Documents\Broker Vision Documents\"

    ' ''''''''''' Broker Vision (Jeddah)
    Public strConn As String = "data source=BV-Server;initial catalog=Oasis-IBS-BrokerVision;user id=sa;password=flatron"
    Public FTPUserName As String = "brokervision/admin_oasis"
    Public FTPPassword As String = "Flatron@1984"
    Public FTPAddress As String = "\\BV-Server\Documents\"

    'VPN
    'Public strConn As String = "data source=7.193.22.84;initial catalog=Oasis-IBS-Indemnity;user id=sa;password=flatron"

    Public cnn, cnn1, cnn2, cnn3, cnn4 As New SqlConnection(strConn)

    Public rptViewer As New ReportViewer

    Public SelClientName, SelPolInsurComp, PWD, SelPolClsOfBus, SelPolNo, SelDate, SelAccNo, SelAccName, SelProspectName, SelEmpName As String
    Public SelClientID, CurrentUserID, SelCustIDNo, SelEmpID, SelProspectID As Integer

    'Security Parameters
    Public CurrentUser, ClientsProfiles, ClientsProfilesAdmin, SelUserID As String

    Public Mainfrm As New frmMain
    Public IssueSlip As New frmIssueSlipInsurance
    Public Branch, BranchCode As String

    Public Function GetBranches() As ArrayList
        Try
            Dim Branches As New ArrayList

            Branches.Add("Jeddah")
            Branches.Add("Riyadh")
            Branches.Add("Khobar")

            Return Branches
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Function

    Public Function GetBranchCode(ByVal Branch As String) As String
        Try
            If Branch = "Jeddah" Then
                BranchCode = "JED"
            ElseIf Branch = "Riyadh" Then
                BranchCode = "RYD"
            ElseIf Branch = "Khobar" Then
                BranchCode = "KBR"
            End If

            Return BranchCode
        Catch ex As Exception
            If cnn.State = ConnectionState.Open Then
                cnn.Close()
            End If
            MsgBox(ex.ToString)
        End Try
    End Function

    Public Function GetUserEmail(ByVal UserName As String) As String
        Try
            Dim cmd As New SqlCommand("Select Email From Users Where FullName=N'" & UserName & "'", cnn)
            Dim Email As String

            cnn.Open()
            Email = CStr(cmd.ExecuteScalar)
            cnn.Close()

            Return Email
        Catch ex As Exception
            If cnn.State = ConnectionState.Open Then
                cnn.Close()
            End If
            MsgBox(ex.ToString)
        End Try
    End Function

    Public Sub PrintClaimLetter(ByVal ClaimNo As String)
        Try
            Dim dap As New SqlDataAdapter("Select * From Claims Where ClaimNo=N'" & ClaimNo & "'", cnn)

            Dim das As New DataSet

            dap.Fill(das, "Claims")

            If ClaimNo.IndexOf("GEN") > -1 Then
                Dim rpt As New ClaimLetterGEN
                rpt.SetDataSource(das)
                rptViewer.CrystalReportViewer1.ReportSource = rpt
                rptViewer.CrystalReportViewer1.RefreshReport()
                rptViewer.ShowDialog()

            ElseIf ClaimNo.IndexOf("MED") > -1 Then
                Dim rpt As New ClaimLetterMED
                rpt.SetDataSource(das)
                rptViewer.CrystalReportViewer1.ReportSource = rpt
                rptViewer.CrystalReportViewer1.RefreshReport()
                rptViewer.ShowDialog()

            ElseIf ClaimNo.IndexOf("MOT") > -1 Then
                Dim rpt As New ClaimLetterMOT
                rpt.SetDataSource(das)
                rptViewer.CrystalReportViewer1.ReportSource = rpt
                rptViewer.CrystalReportViewer1.RefreshReport()
                rptViewer.ShowDialog()

            End If
        Catch ex As Exception
            If cnn.State = ConnectionState.Open Then
                cnn.Close()
            End If
            MsgBox(ex.ToString)
        End Try
    End Sub

    Public Sub SendEmail(ByVal Subject As String, ByVal Body As String, ByVal Receivers As ArrayList)
        Try

            Dim mail As New MailMessage()

            Dim SmtpServer As New SmtpClient()
            SmtpServer.Credentials = New Net.NetworkCredential("info@oasisoft.net", "Flatron1984")
            'SmtpServer.Port = 80
            SmtpServer.Host = "smtp.oasisoft.net"
            'SmtpServer.EnableSsl = True

            mail.From = New MailAddress("info@oasisoft.net", "Oasis - IBS")

            mail.Subject = Subject
            mail.Body = Body

            mail.IsBodyHtml = True 'Change it as you need

            mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure

            For Each rec As String In Receivers
                mail.To.Add(rec)
            Next

            SmtpServer.Send(mail)

            mail.Dispose()

        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
End Module
